package ganga.sportsman;

import ganga.custodian.CustodianApplication;
import ganga.custodian.DBHelper;
import ganga.custodian.Helper;
import ganga.custodian.LoggingService;
import ganga.events.NotificationID;
import ganga.sensors.AccelerometerMonitor;
import ganga.ui.StatusDisplay;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;

import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Application class works as a dock for other components. It share data across
 * multiple Activities and Services. Realized as singleton. When writing an
 * Android app, you're guaranteed to only have one instance of the android.app.
 * Application class so it's safe ( and recommended by the Google Android team )
 * to treat it as a Singleton.
 * 
 * @see http://www.androidcookbook.com/Recipe.seam?recipeId=1218
 * 
 *      {@link CustodianApplication}
 * @author Apocrypha
 */
public final class Application extends android.app.Application {
	/**
	 * As the name suggests, its the context of current state of the
	 * application/object. It lets newly created objects understand what has
	 * been going on. Typically you call it to get information regarding another
	 * part of your program (activity, package/application)
	 */
	public static Context context;

	public LoggingService service;
	public long activityNum = 0;
	public boolean onExit = false;

	/**
	 * Data units.
	 */
	public static enum Unit {
		SI, IMPERIAL;
	}

	@Override
	public final void onCreate() {
		super.onCreate();

		instance = this;
		context = getApplicationContext();
	}

	/**
	 * Can be called when the application object is terminated. Note that there
	 * is no guarantee of this method handler's being called. s terminated by
	 * the kernel in order to free resources for other applications, the process
	 * will be terminated without warning and without a call to the application
	 * object's onTerminate handler.
	 * 
	 * @see android.app.Application#onTerminate()
	 */
	@Override
	public final void onTerminate() {
		CustodianApplication.getInstance().terminate();
		super.onTerminate();
	}

	/**
	 * Отображение уведомления в строке состояния.
	 * 
	 * @param context
	 * @param ticket
	 * @param title
	 * @param content
	 */
	public void displayNotify(android.content.Context context, CharSequence ticket, CharSequence title,
			CharSequence content, NotificationID nID) {
	}

	/**
	 * Singleton
	 */
	private static Application instance;

	/**
	 * Returns the application instance
	 */
	public static Application getInstance() {
		return instance;
	}

	public void runTest() {
		Helper.log("Test started");
		Intent serviceIntent = new Intent(context, LoggingService.class);

		context.startService(serviceIntent);
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		context.stopService(serviceIntent);

		Helper.log("Test finished");
	}
}// UI Application